<template>
  <div class="content">
    <BreadNav
      :location="location"
      :routers="routers"
    />
    <main>
      <div class="time_list">
        <ul>
          <li
            v-for="(item, index) in timerList"
            :key="index"
          >
            <span>{{ item.created_at.slice(0, 10) }}</span>
            <a
              href="javascript:void(0);"
              @click="clickFn(item)"
            >
              {{ item.title }}
            </a>
          </li>
        </ul>
      </div>
    </main>
    <Footer />
  </div>
</template>

<script>
import BreadNav from '@/components/BreadNav.vue'
import Footer from '@/components/Footer.vue'
import { getArticleList } from '@/api/article'
export default {
  components: {
    BreadNav,
    Footer
  },
  data() {
    return {
      location: '时间轴',
      routers: 'shijianzhou',
      arr1: [1, 2, 3, 4, 5, 6, 7],
      timerList: [],
      totalCount: null,
      page: 1,
      lock: false
    }
  },
  created() {
    this.getData()
  },
  mounted() {
    window.addEventListener('scroll', this.getScroll)
  },
  methods: {
    getScroll(event) {
      if (this.lock) return
      const scrollBottom =
        event.target.documentElement.scrollHeight -
        event.target.documentElement.scrollTop -
        event.target.documentElement.clientHeight
      if (scrollBottom < 1) {
        this.lock = true
        this.page++
        this.getData()
        this.lock = false
      }
    },
    async getData() {
      const opt = {
        page: this.page,
        per_page: 20,
        timer: 0
      }
      const res = await getArticleList(opt)
      this.timerList = [...this.timerList, ...res.data.data]
      this.totalCount = res.data.totalCount
      setTimeout(() => {
        this.lock = false
      }, 500)
    },
    clickFn(v) {
      switch (v.channel_id) {
        case 1: // 博客日记
          this.$router.push({
            path: '/bokeriji',
            query: {
              id: v.id
            }
          })
          break
        case 2: // 闲言碎语
          this.$router.push({
            path: '/xianyansuiyu',
            query: {
              id: v.id
            }
          })
          break
        case 4: // 相册
          this.$router.push({
            path: '/wodexiangce',
            query: {
              id: v.id
            }
          })
          break
        case 5: // 前端分享
          this.$router.push({
            path: '/qianduan',
            query: {
              id: v.id
            }
          })
          break
        default:
          this.$router.push({
            path: '/yulubu',
            query: {
              id: v.id
            }
          })
          break
      }
    }
  }
}
</script>

<style lang="scss" scoped>
// 宽度大于1201px时
@media screen and (min-width: 1201px) {
  .content {
    width: 1200px;
    margin: 0 auto;
  }
}

// 宽度小于1200px时
@media screen and (max-width: 1200px) {
  .content {
    margin: 0 40px;
  }
}

@media only screen and (max-width: 480px) {
  body .content main .time_list ul li span {
    width: 100%;
    text-indent: 2em;
    font-size: 12px;
  }
  .content {
    margin: 0 15px;
  }
  .time_list ul li a {
    padding-left: 24px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
  }
  .time_list ul li {
    overflow: hidden;
  }
  body .content main .time_list {
    padding: 20px 10px 20px 15px;
  }
  body .content main .time_list ul:before {
    left: 6px;
  }
  .time_list ul li a:before {
    top: 10px;
  }
}

.content {
  main {
    width: 100%;
    .time_list {
      padding: 30px;
      background: #fff;
      margin-bottom: 20px;
      border-radius: 3px;
      ul {
        position: relative;
        width: 100%;
        li {
          line-height: 36px;
          span {
            color: #999;
            margin-right: 20px;
            width: 90px;
            display: block;
            float: left;
          }
          a {
            position: relative;
            padding-left: 30px;
          }
          a:before {
            content: ' ';
            height: 10px;
            width: 10px;
            border: 2px solid #cccaca;
            background: #fff;
            position: absolute;
            top: 4px;
            left: 0px;
            border-radius: 50%;
            transition: all 0.5s;
          }
          a:hover:before {
            background: #e01109;
          }
          a:hover {
            color: #e01109;
          }
        }
      }
      ul:before {
        position: absolute;
        content: '';
        width: 2px;
        height: 100%;
        background: #cccaca;
        left: 116px;
      }
    }
  }
}
</style>
